# Some of the targets in here use bashisms, so force bash as the interpreter.
SHELL=/bin/bash
ifeq ($(wildcard ${SHELL}),)
$(error Prerequisite ${SHELL} not found)
endif

export SEL4_CMDLINE="console=0x3f8 debug=0x2f8 max_num_nodes=8"
harddisk-images: $(patsubst %,%-harddisk-image,$(apps))

%-harddisk-image: % common kernel_elf
	@echo "[COBBLER] $@"
	$(Q)$(SEL4_COMMON)/cobbler -k "$(STAGE_BASE)/kernel.elf" -a $(SEL4_CMDLINE) \
		-o "$(IMAGE_ROOT)/$@-$(ARCH)-$(PLAT)" "$(STAGE_BASE)/bin/$<" 2>&1 \
		| while read line; do echo " [COBBLER] $$line"; done; \
		exit $${PIPESTATUS[0]}

%-image: export PATH := $(STAGE_ROOT)/dite:$(PATH)
%-image: % kernel_elf common dite
	@echo "[GEN_IMAGE] $@"
	$(Q)$(call cp_if_changed, "$(STAGE_BASE)/kernel.elf", \
		"$(IMAGE_ROOT)/kernel-$(ARCH)-$(PLAT)")
	@echo " [DITE] $< -> $@-$(ARCH)-$(PLAT)"
	${Q}dite -D 0 \
		-o ${IMAGE_ROOT}/$@-$(ARCH)-$(PLAT)\
		${STAGE_BASE}/bin/$< 2>&1 \
		| while read line; do echo " [DITE] $$line"; done; \
		exit $${PIPESTATUS[0]}
